from ddt import ddt, data, unpack
from unittest import TestCase
from selenium import webdriver
from DeleteCardData import DeleteCardData
from DeleteCardOperation import DeleteCardOperation
from DBUtils import DBUtils


@ddt
class TestDeleteCard(TestCase):
    @data(*DeleteCardData.deletecard_success_data)
    @unpack
    def testDeleteCard1(self, casename, username, password, expect):
        # 开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("http://localhost:90")
        driver.maximize_window()

        dbutils = DBUtils()
        before_result = dbutils.select('select id from bankcard where cardBank = "伊拉克国民银行" and cardNum = "1234567891548790" and type = "2"')

        # 执行删除
        deletecard = DeleteCardOperation()
        deletecard.deletecard_success(driver, username, str(int(password)))
        # 获取删除实际结果
        result = deletecard.delete_success_result(before_result[0])
        if result != int(expect):
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, int(expect))

    @data(*DeleteCardData.deletecard_cancel_data)
    @unpack
    def testDeleteCard1(self, casename, username, password, expect):
        # 开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("http://localhost:90")
        driver.maximize_window()

        dbutils = DBUtils()
        before_result = dbutils.select(
            'select id from bankcard where cardBank = "伊拉克国民银行" and cardNum = "1234567891548790" and type = "1"')

        # 执行删除取消
        deletecard = DeleteCardOperation()
        deletecard.deletecard_cancel(driver, username, str(int(password)))
        # 获取删除取消实际结果
        result = deletecard.delete_cancel_result(before_result[0])
        if result != int(expect):
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, int(expect))
